<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
        #canvas {
            display: block;
            margin: 200px auto;
            border: 1px solid #000;
            box-shadow: 1px 1px #ccc;
        }
    </style>
</head>

<body>
    <canvas id="canvas" height="600" width="700"></canvas>

    <script>
        const canvas = document.getElementById("canvas");
        const ctx = canvas.getContext("2d");
        ctx.beginPath()
        ctx.strokeStyle = 'blue' // 设置绘图的描边颜色或样式
        ctx.moveTo(200, 250);
        ctx.lineTo(500, 250);
        ctx.stroke();

        ctx.fillStyle = 'red' // 文字的颜色
        ctx.font = '18px Arial' // 文本样式
        ctx.fillText('canvas绘制直线', 280, 220) // 在指定位置绘制填充文本
        ctx.closePath();
    </script>
</body>

</html>